/**
 * this class output two graphs,one is a triangle,the other is a diamond.
 */
package cn.netjava.softkid.chapter01;

/**
 * @author softkid
 * @version v1.0.0
 */
public class GraphDemo {
	/**
	 * 
	 * @param num:the base of the triangle
	 * @param str:which the triangle made of 
	 */
	public void triangle(int num,String str)
	{
		StringBuffer space = new StringBuffer();
		int len = str.length();
		while(len-->0)
		{
			space.append(" ");
		}
		for(int i=1;i<=num;i+=2)
		{
			for(int j=1;j<=(num-i)/2;j++)
			{
				buf.append(space);
			}
			for(int k=1;k<=i;k++)
			{
				buf.append(str);
			}
			buf.append("\n");
		}
	}
	
	/**
	 * 
	 * @param num:Diagonal of the diamond
	 * @param str:which the diamond made of
	 */
	public void diamond(int num,String str)
	{
		StringBuffer space = new StringBuffer();
		int len = str.length();
		while(len-->0)
		{
			space.append(" ");
		}
		for(int i=1;i<=num;i+=2)
		{
			for(int j=1;j<=(num-i)/2;j++)
			{
				buf.append(space);
			}
			for(int k=1;k<=i;k++)
			{
				buf.append(str);
			}
			buf.append("\n");
		}
		if(num%2==0)
			num-=1;
		for(int i=num-2;i>=1;i-=2)
		{
			for(int j=1;j<=(num-i)/2;j++)
			{
				buf.append(space);
			}
			for(int k=1;k<=i;k++)
			{
				buf.append(str);
			}
			buf.append("\n");
		}
	}
	
	/**
	 * output the triangle and the diamond
	 */
	public String toString()
	{
		return buf.toString();
	}

	/**
	 * main method 
	 * @param args
	 */
	public static void main(String[] args) 
	{
		java.util.Scanner sc = new java.util.Scanner(System.in);
		System.out.println("please enter a number for the length of the base of the triangle or the Diagonal of the diamond:");
		int num = sc.nextInt();
		System.out.println("please enter a String:");
		String str = sc.next();
		GraphDemo graph = new GraphDemo();
		graph.triangle(num, str);
		graph.diamond(num, str);
		System.out.println(graph);
	}
	StringBuffer buf = new StringBuffer();
}
